package ua.edu.nuos.jeetraining2012.cms.entity;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * Instructors entity bean.
 * <p/>
 * Java bean that store information about course instructors.
 *
 * @author Victor N. Ganichev victor.ganichev@gmail.com
 * @version 1.0 Date: 02.05.13 Time: 14:50
 * @since 1.0
 */
@Entity
@Table(name = "instructors")
public class CourseInstructorEntity implements Serializable {

    /**
     * Instructor ID
     * <p/>
     * Auto-generated identifier, Primary Key.
     */
    @Id
    @SequenceGenerator(
            name = "instructors_id_seq",
            sequenceName = "instructors_id_seq",
            allocationSize = 1
    )
    @GeneratedValue(
            strategy = GenerationType.SEQUENCE,
            generator = "instructors_id_seq"
    )
    @Column(
            name = "id",
            nullable = false,
            insertable = true,
            updatable = false,
            length = 11,
            precision = 0,
            columnDefinition = "SERIAL"
    )
    @NotNull(message = "Instructor id can't be null")
    @Min(1)
    private long id;

    /**
     * FK to users.id
     */
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(
            name = "user_id",
            nullable = false,
            unique = true
    )
    @NotNull(message = "User_id can't be null")
    private UserEntity userId;


    /**
     * Instructor description.
     * <p/>
     * Text description of instructor. Who, experience etc.
     */
    @Column(
            name = "description",
            nullable = false,
            insertable = true,
            updatable = true,
            length = 2048
    )
    @NotNull(message = "Description can't be null")
    @Basic(optional = false)
    @Size(min = 0, max = 2048)
    private String description;

    /**
     * Course instructor role.
     * <p/>
     * Refer to {@link ua.edu.nuos.jeetraining2012.cms.dto.predefined.StandardInstructorRoles} for all possible and valid roles.
     */
    @Column(
            name = "instructor_role",
            nullable = false,
            insertable = true,
            updatable = true,
            length = 16
    )
    @Basic(optional = false)
    @NotNull(message = "Instructor role can't be null")
    @Size(min = 0, max = 16)
    private String role;

    /**
     * Instructor additional contacts.
     * <p/>
     * In addition to user contacts, instructor can place its own additional contacts.
     * <br/>
     * Optional.
     */
    @Column(
            name = "additional_contacts",
            nullable = true,
            insertable = true,
            updatable = true,
            length = 2048
    )
    @Basic(optional = true)
    @Size(min = 0, max = 2048)
    private String additionalContacts;

    /**
     * Instructor photo.
     * <p/>
     * Link to instructor's photo. County should know its own heroes.
     * <br/>
     * Optional.
     */
    @Column(
            name = "photo",
            nullable = true,
            insertable = true,
            updatable = true,
            length = 512
    )
    @Basic(optional = true)
    @Size(min = 0, max = 512)
    private String photo;


//  Default constructor
    public CourseInstructorEntity() {}

// Getters & Setters

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public UserEntity getUserId() {
        return userId;
    }

    public void setUserId(UserEntity userId) {
        this.userId = userId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getAdditionalContacts() {
        return additionalContacts;
    }

    public void setAdditionalContacts(String additionalContacts) {
        this.additionalContacts = additionalContacts;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

// Overrides

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CourseInstructorEntity that = (CourseInstructorEntity) o;

        if (id != that.id) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return (int) (id ^ (id >>> 32));
    }

    @Override
    public String toString() {
        return "CourseInstructorEntityBean {" +
                "id:" + id +
                ", userId:" + userId +
                ", description:'" + description + '\'' +
                ", role:'" + role + '\'' +
                ", additionalContacts:'" + additionalContacts + '\'' +
                ", photo:'" + photo + '\'' +
                '}';
    }
}
